<?xml version="1.0" encoding="UTF-8" ?>

<!-- One XLST that use HTML + CSS to display all the relevant information about a club, 
with a parameter to receive the club identification. -->

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
>

	<xsl:output method="xml" indent="yes"/>
	
	<xsl:template match="/">
	
	<xsl:processing-instruction name="xml-stylesheet">type="text/xsl" href="xslt/team_page.xslt"</xsl:processing-instruction>
	
	
		<teams>
			<xsl:for-each select="/league/teams/team">
				<xsl:variable name="currentTeam" select="@id" />
			
				<team>
					<xsl:attribute name="id" select="$currentTeam" />
					<name><xsl:value-of select="teamName" /></name>
					<foundation><xsl:value-of select="foundation" /></foundation>
					<acronym><xsl:value-of select="acronym" /></acronym>
					<city><xsl:value-of select="city" /></city>
					<description><xsl:value-of select="description" /></description>
					<website><xsl:value-of select="website" /></website>
					<stadium>
						<xsl:variable name="stadiumId" select="./main_stadium/@stadiumId" />
						<xsl:attribute name="stadiumId"  select="$stadiumId" />					
						<xsl:value-of select="/league/stadiums/stadium[@id = $stadiumId]/stadiumName" />
					</stadium>

					<xsl:apply-templates select="squad" />

					<xsl:apply-templates select="history" />


				</team>			
			</xsl:for-each>
		</teams>
	</xsl:template>
	
	<xsl:template match="squad">
		<squad>
		<xsl:for-each select="./squad_player">
		<xsl:sort select="number" data-type="number" order="ascending"/>
		<player>
			<xsl:variable  name="playerId" select="@playerId" />
			<xsl:variable  name="player" select="/league/players/player[@id = $playerId]" />
			<xsl:attribute name="id" select="@playerId"/>
			<name><xsl:value-of select="$player/playerName"/></name>
			<position><xsl:value-of select="$player/@position"/></position>
			<nickname><xsl:value-of select="$player/nickname"/></nickname>
			<nacionality><xsl:value-of select="$player/nationality"/></nacionality>
			<playerNumber><xsl:value-of select="number" /></playerNumber>
		</player>
		</xsl:for-each>

		</squad>
	</xsl:template>
	
	<xsl:template match="history">
		<history>
			<xsl:attribute name="count" select="count(./team_award)" />

		<xsl:for-each select="./team_award">
		<xsl:sort select="@date" data-type="text" order="ascending"/>
		<award>
			<date><xsl:value-of select="@date"/></date>
			<title><xsl:value-of select="."/></title>
		</award>
		</xsl:for-each>
		</history>
	</xsl:template>

</xsl:stylesheet>
